from rest_framework.serializers import ModelSerializer

from course.models import CourseCategory, Course, Teacher, CourseChapter,CourseLesson


class CourseCategoryModelSerializer(ModelSerializer):
    class Meta:
        model = CourseCategory
        fields = ("id", "name")


class TeacherModelSerializer(ModelSerializer):
    class Meta:
        model = Teacher
        fields = ("id", "name", "title", "signature", "image", "brief")


class CourseModelSerializer(ModelSerializer):
    teacher = TeacherModelSerializer()
    class Meta:
        model = Course
        fields = ("id", "name", "course_img", "students", "lessons", "pub_lessons",
                  "price", "teacher", "lesson_list",
                  "discount_name", "real_price", "active_time")

# class CourseOneserializer(ModelSerializer):
#     """单个课程列表"""
#     teacher=TeacherModelSerializer()
#     class Meta:
#         model=Course
#         fields=("id", "name", "course_img", "students", "lessons", "pub_lessons",
#                   "price", "teacher", "level_name", "brief_html","file_path")

class CourseOneserializer(ModelSerializer):
    teacher = TeacherModelSerializer()

    class Meta:
        model = Course
        fields = ("id", "name", "course_img", "students", "lessons", "pub_lessons",
                  "price", "teacher", "lesson_list", "course_category", "level_message",
                  "course_chapter_list", "brief_html", "file_path",
                  "discount_name", "real_price", "active_time")
        # course_chapter_list  是一级标题
        # lesson_list  是二级标题
        extra_kwargs = {
            "level_message": {
                "read_only": True
            }
        }




# class CourseLessonModelSerializer(ModelSerializer):
#     """课程课时信息"""
#
#     class Meta:
#         model = CourseLesson
#         fields = ['id', "name", "free_trail", "duration"]
#
#
# class CourseChapterModelSerializer(ModelSerializer):
#     # 一堆多 需要指定参数 many=True
#     coursesections = CourseLessonModelSerializer(many=True)
#
#     class Meta:
#         model = CourseChapter
#         fields = ['id', 'chapter', 'name', "coursechapters"]